home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / APPMORE.ZIP / APPMORE.C < prev    next >
C/C++ Source or Header  |  1993-04-08  |  14KB  |  431 lines

  1. /*-------------------------------------------------------------------------
  2.  appmore.c
  3.  
  4.  a multiple launch utility for AppBar
  5.  
  6.  by
  7.  GMP van kempen
  8.  NEVERnever Software 1992
  9.  
  10.  History:
  11.     1.0     first try. Removed IsDosExe(), rely on IsDosWindow() now. Fixed
  12.         bug with auto-bounceback. Removed AppMore Start & Exit sounds.
  13.         Added SystemMenu with About/Close/Cancel/Setup/QuickLoad/Minimize
  14.         buttons and functions. Changed default screen place.
  15.     4.00.1  Updated to the AppBar 4.00 family.
  16.  
  17. ---------------------------------------------------------------------------*/
  18. //compile with the strictest error checking
  19. #define STRICT
  20. #include <windows.h>
  21. #include <windowsx.h>
  22. #include <shellapi.h>
  23. #include <string.h>
  24. #include <stdio.h>
  25. #include <ctl3d.h>
  26. #include <memory.h>
  27. #include "appmore.h"
  28.  
  29. #define MAKECHILD(a,b,c,d,e,f,g,h) CreateWindow(a,b,WS_CHILD | WS_VISIBLE | c,d,e,f,g,hWnd,h,hInst,(LPSTR) NULL)
  30. #define MAKEBUTTON(a,b,c,d,e,f)       MAKECHILD("button",a,BS_PUSHBUTTON | BS_OWNERDRAW,b,c,d,e,f)
  31. #define MAKESTATIC(a,b,c,d)       MAKECHILD("static",NULL,SS_BLACKRECT,a,b,c,d,(HMENU)-1)
  32. #define MAKEBORDER(a,b,c,d)       MAKECHILD("static",NULL,SS_WHITERECT,a,b,c,d,(HMENU) -1)
  33.  
  34. APPBARBUTTONS     AppButton[MAXAPPS], AppButtonDefault;
  35. APPSYSTEM     AppSystem;
  36. APPSOUND     AppSound;
  37. APPWINDOW     AppWindow = {1, MAXAPPS, 32, 32};
  38. APPMAXSIZE     AppMaxSize;
  39. char         szAppName[] = "AppMore", szTitleName[] = "AppMore 4.0";
  40. char         szSectionName[256];
  41. int         iCurrent = 0, iActive = 0, iKey = 1;
  42. int         cxChar, cyChar, iShuffledButton, FirstAppButton = 1;
  43. HWND         hWndMain, hWndButton[MAXAPPS], hWndCurrentButton;
  44. HINSTANCE     hInst;
  45. HBITMAP         hAppLogo, hNNever, hbBlank, hbKeyb;
  46. HBITMAP      hbPressed;
  47. HICON         hSystem, hBlank, hPressed, hQuickLoad, hKeybOn;
  48. HICON         hPressed2, hSystem2;
  49. BOOL         bFirst = TRUE;
  50. BOOL         bQuickLoad = FALSE, bMoveButton = FALSE;
  51. BOOL         bButtonMoved = FALSE;
  52. LPDRAWITEMSTRUCT lpIconDIS;
  53. BOOL         bKeyboardOn = FALSE, bExecuteProg = TRUE, bShuffleButton = FALSE;
  54. short         Rows, xSize, ySize;
  55.  
  56.  
  57. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  58.            LPSTR lpszCmdLine, int nCmdShow)
  59.     {
  60.     HWND    hWnd;
  61.     MSG     msg;
  62.     WNDCLASS    wndclass;
  63.     short    xScreen, yScreen;
  64.  
  65.     lstrcpy(szSectionName, lpszCmdLine);
  66.     AppSystem.SectionNumber = VerifySectionName(szSectionName);
  67.     InitDefaultButton();
  68.     IniRead();
  69.     if(AppSystem.SectionNumber == 0)
  70.     {
  71.     AppSystem.Buttons = 0;
  72.     AppSystem.Columns = 1;
  73.     }
  74.  
  75.     if(!hPrevInstance)
  76.     {
  77.     wndclass.style            = CS_HREDRAW | CS_VREDRAW;
  78.     wndclass.lpfnWndProc        = WndProc;
  79.     wndclass.cbClsExtra        = 0;
  80.     wndclass.cbWndExtra        = 0;
  81.     wndclass.hInstance        = hInstance;
  82.     wndclass.hIcon            = LoadIcon(NULL, MAKEINTRESOURCE(1000));
  83.     wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  84.     wndclass.hbrBackground        = GetStockBrush(LTGRAY_BRUSH);
  85.     wndclass.lpszMenuName        = NULL;
  86.     wndclass.lpszClassName        = szAppName;
  87.  
  88.     RegisterClass(&wndclass);
  89.     }
  90.  
  91.     SetCursor(LoadCursor(NULL, IDC_WAIT));
  92.     hInst = hInstance;
  93.  
  94.     Ctl3dRegister(hInst);
  95.     Ctl3dAutoSubclass(hInst);
  96.  
  97.     // add the SystemButton.
  98.     AppWindow.nButtons = AppSystem.Buttons+1;
  99.     AppWindow.nColumns = AppSystem.Columns;
  100.  
  101.     // try to add enough buttons to fill all the columns
  102.     while(AppWindow.nButtons % AppWindow.nColumns)
  103.     {
  104.     AppWindow.nButtons++;
  105.     if(AppWindow.nButtons > MAXAPPS)
  106.         break;
  107.     }
  108.     if(AppWindow.nButtons % AppWindow.nColumns)
  109.     {
  110.     AppWindow.nButtons = AppSystem.Buttons+1;
  111.     AppWindow.nColumns = 1;
  112.     }
  113.  
  114.     AppMaxSize = CalculateAppMaxSize();
  115.  
  116.     if(AppSystem.Left == -1)
  117.     xScreen = GetSystemMetrics(SM_CXSCREEN) - (AppWindow.cxButton*(AppWindow.nColumns+1));
  118.     else
  119.     xScreen = AppSystem.Left;
  120.     if(AppSystem.Top == -1)
  121.     yScreen = GetSystemMetrics(SM_CYSCREEN) - (AppWindow.cyButton*(AppWindow.nButtons/AppWindow.nColumns));
  122.     else
  123.     yScreen = AppSystem.Top;
  124.  
  125.  
  126.     if(AppSystem.SectionNumber == 0)
  127.     AppWindow.nButtons = 0;
  128.  
  129.     AppSystem.Border = 0;
  130.     Rows = AppWindow.nButtons/AppWindow.nColumns;
  131.     xSize = AppWindow.cxButton*AppWindow.nColumns;
  132.     xSize += (AppWindow.nColumns+1)*AppSystem.Border;
  133.     ySize = AppWindow.cyButton*Rows + (Rows+1)*AppSystem.Border;
  134.  
  135.     hWnd = CreateWindow(szAppName, szTitleName,
  136.             WS_POPUP | WS_VISIBLE,
  137.             xScreen, yScreen, xSize, ySize,
  138.             NULL, NULL, hInstance,NULL);
  139.  
  140.     hWndMain = hWnd;
  141.     SetTimer(hWnd, ID_TIMER, 1000, NULL);
  142.  
  143.     LoadAppMoreResources();
  144.  
  145.     strcpy(szBuffer, szTitleName);
  146.     strcat(szBuffer, " - ");
  147.     strcat(szBuffer, szSectionName);
  148.     SetWindowText(hWnd, szBuffer);
  149.  
  150.     SetCursor(LoadCursor(NULL, IDC_ARROW));
  151.  
  152.     ShowWindow(hWnd, SW_SHOWNORMAL);
  153.     UpdateWindow(hWnd);
  154.  
  155.     while(GetMessage(&msg, NULL, 0, 0))
  156.     {
  157.     TranslateMessage(&msg);
  158.     DispatchMessage(&msg);
  159.     }
  160.  
  161.     Ctl3dUnregister(hInst);
  162.     return msg.wParam;
  163.     } /* end WinMain */
  164.  
  165. /*------------------------------------------------------------------------/
  166.    FUNCTION: WndProc()
  167. /------------------------------------------------------------------------*/
  168. long WINAPI WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  169.     {
  170.     static DLGPROC lpfnSystemDlgProc, lpfnAboutDlgProc;
  171.     static HICON   hIcon[MAXAPPS];
  172.     char       szDropFile[MAXFILECHARS], SystemSection[256];
  173.     TEXTMETRIC       tm;
  174.     POINT       DropPoint;
  175.     int        i, iDropButton = 0, iDropped;
  176.     HBRUSH       hbrush;
  177.     UINT       DroppedFiles;
  178.     int        xPos, yPos;
  179.  
  180.     switch (message)
  181.     {
  182.     case WM_CREATE:
  183.         tm = RetrieveTextMetrics(hWnd);
  184.         cxChar = tm.tmAveCharWidth;
  185.         cyChar = tm.tmHeight;
  186.         if(AppSystem.SectionNumber == 0)
  187.         {
  188.         AppWindow.nButtons = 0;
  189.         hAppLogo = LoadBitmap(hInst, "AppLogo");
  190.         hNNever = LoadBitmap(hInst, "NNever");
  191.         lpfnAboutDlgProc = (DLGPROC) MakeProcInstance((FARPROC)AboutDlgProc, hInst);
  192.         DialogBox(hInst, "AboutDlg", hWnd, lpfnAboutDlgProc);
  193.         FreeProcInstance((FARPROC)lpfnAboutDlgProc);
  194.         KillTimer(hWnd, ID_TIMER);
  195.         DeleteBitmap(hAppLogo);
  196.         DeleteBitmap(hNNever);
  197.         PostQuitMessage(0);
  198.         }
  199.         LoadAllButtonIcons(hIcon);
  200.         if(AppSystem.Border)
  201.         Ctl3dSubclassCtl(MAKEBORDER(0, 0, xSize, ySize));
  202.         for(i=0;i<AppWindow.nButtons;i++)
  203.         {
  204.         xPos=AppSystem.Border+(AppSystem.Border+AppWindow.cxButton)*(i/(AppWindow.nButtons/AppWindow.nColumns));
  205.         yPos=AppSystem.Border+(AppSystem.Border+AppWindow.cyButton)*(i%(AppWindow.nButtons/AppWindow.nColumns));
  206.         if(AppSystem.Border)
  207.             Ctl3dSubclassCtl(MAKESTATIC(xPos-1, yPos-1,
  208.                 AppWindow.cxButton+2, AppWindow.cyButton+2));
  209.         hWndButton[i] = MAKEBUTTON(NULL, xPos, yPos,
  210.                 AppWindow.cxButton, AppWindow.cyButton,
  211.                 ID_BUTTON1+i);
  212.         }
  213.         SetNormalChildCursor();
  214.         DragAcceptFiles(hWnd, TRUE);
  215.         return 0;
  216.  
  217.     case WM_SYSCOLORCHANGE:
  218.         Ctl3dColorChange();
  219.         return 0;
  220.  
  221.     case WM_CTLCOLOR:
  222.         hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
  223.         if(hbrush != (HBRUSH) FALSE)
  224.         return hbrush;
  225.         else
  226.         return DefWindowProc(hWnd, message, wParam, lParam);
  227.  
  228.     case WM_SYSCHAR:
  229.     case WM_SYSKEYUP:
  230.         return 0;
  231.  
  232.     case WM_SYSKEYDOWN:
  233.         return ProcessSystemKeys((int) wParam);
  234.  
  235.     case WM_KEYDOWN:
  236.         return KeyboardInterface((int)wParam);
  237.  
  238.     case WM_DRAWITEM:
  239.         lpIconDIS = (LPDRAWITEMSTRUCT) lParam;
  240.         iCurrent = (int) (lpIconDIS->CtlID - ID_BUTTON1);
  241.         hWndCurrentButton = lpIconDIS->hwndItem;
  242.         if(iCurrent == SYSTEM_MENU)
  243.         {
  244.         DrawIcon(lpIconDIS->hDC, 0, 0, hSystem);
  245.         if(bQuickLoad)
  246.             DrawIcon(lpIconDIS->hDC, 0, 0, hQuickLoad);
  247.         }
  248.         if(iCurrent >= FIRST_APPLICATION)
  249.         {
  250.         if(hIcon[iCurrent-1] != NULL)
  251.             {
  252.             if(AppButton[iCurrent-1].ButtonLook)
  253.             DrawIcon(lpIconDIS->hDC, 0, 0, hBlank);
  254.             DrawIcon(lpIconDIS->hDC, 0, 0, hIcon[iCurrent-1]);
  255.             }
  256.         else
  257.             DrawIcon(lpIconDIS->hDC, 0, 0, hBlank);
  258.         if(AppButton[iCurrent-1].ProgStatus == ALIVE)
  259.             DrawIcon(lpIconDIS->hDC, 0, 0, hPressed);
  260.         }
  261.         break;
  262.  
  263.     case WM_TIMER:
  264.         CheckProgStatus();
  265.         if(AppSystem.StayInFront == 1)
  266.         if(GetActiveWindow() != hWnd)
  267.             SetWindowPos(hWnd, NULL, 0, 0, 0, 0,
  268.                   SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  269.         return 0;
  270.  
  271.     case WM_COMMAND:
  272.          // If a button was clicked, then it is the currently selected tool.
  273.         if((HIWORD(lParam) == BN_CLICKED && AppSystem.DoubleClick == 0) || (HIWORD(lParam) == BN_DOUBLECLICKED && AppSystem.DoubleClick == 1))
  274.         {
  275.         if((wParam >= (UINT) ID_BUTTON1) && (wParam <= (UINT) (ID_BUTTON1 + AppWindow.nButtons)))
  276.             {
  277.             iCurrent = 0;
  278.             while((ID_BUTTON1 + iCurrent) != (int) wParam)
  279.             iCurrent++; // just increment i !!
  280.             if(iCurrent == SYSTEM_MENU)
  281.             {
  282.             lpfnSystemDlgProc = (DLGPROC) MakeProcInstance((FARPROC)SystemDlgProc, hInst);
  283.             DialogBox(hInst, "SystemDlg", hWnd, lpfnSystemDlgProc);
  284.             FreeProcInstance( (FARPROC) lpfnSystemDlgProc);
  285.             break;
  286.             }
  287.             if(iCurrent >= FIRST_APPLICATION)
  288.             {
  289.             if(!bQuickLoad)
  290.                 {
  291.                 CheckProgStatus();
  292.                 StartOrCloseProgram(iCurrent-1); // start and close programs linked to a button.
  293.                 }
  294.             else
  295.                 {
  296.                 if(bShuffleButton)
  297.                 {
  298.                 bShuffleButton = FALSE;
  299.                 SetNormalChildCursor();
  300.                 AppButton[iCurrent-1] = AppButton[iShuffledButton-1];
  301.                 hIcon[iCurrent-1] = hIcon[iShuffledButton-1];
  302.                 SaveButton(iCurrent-1);
  303.                 InvalidateRect(hWndButton[iCurrent], NULL, TRUE);
  304.                 InvalidateRect(hWndButton[iShuffledButton], NULL, TRUE);
  305.                 UpdateWindow(hWnd);
  306.                 }
  307.                 else
  308.                 {
  309.                 bShuffleButton = TRUE;
  310.                 SetShuffleChildCursor();
  311.                 iShuffledButton = iCurrent;
  312.                 }
  313.                 }
  314.             }
  315.             }
  316.         }
  317.         break;   /* end WM_COMMAND */
  318.  
  319.        case WM_DROPFILES:
  320.         if(AppSound.EnableSound != 0)
  321.         if(stricmp(AppSound.DropFile, "<none>") != 0)
  322.             sndPlaySound(AppSound.DropFile, SND_ASYNC | SND_NODEFAULT);
  323.         DragQueryPoint((HANDLE) wParam, (LPPOINT) &DropPoint);
  324.         iDropButton = (DropPoint.y/AppWindow.cyButton);
  325.         iDropButton += (AppWindow.nButtons/AppWindow.nColumns)*(DropPoint.x/AppWindow.cxButton);
  326.         DroppedFiles = DragQueryFile((HANDLE) wParam, 0xFFFF, (LPSTR) NULL, 0);
  327.         if(!bQuickLoad)
  328.         {
  329.         if(iDropButton-1 >= 0)
  330.             {
  331.             for(i=0;i<DroppedFiles;i++)
  332.             {
  333.             DragQueryFile((HANDLE) wParam, i, szDropFile, sizeof(szDropFile));
  334.             // add szDropfile to existing parameters.
  335.             strcpy(szBuffer, AppButton[iDropButton-1].Params);
  336.             strcat(szBuffer, " ");
  337.             strcat(szBuffer, szDropFile);
  338.             ProgExec(hWnd, AppButton[iDropButton-1].ProgName, szBuffer, AppButton[iDropButton-1].StartDir, AppButton[iDropButton-1].ShowMode);
  339.             }
  340.             }
  341.         else
  342.             {
  343.             for(i=0;i<DroppedFiles;i++)
  344.             {
  345.             DragQueryFile((HANDLE) wParam, i, szDropFile, sizeof(szDropFile));
  346.             ShellExecute(hWnd, "open", szDropFile, NULL, NULL, SW_SHOWNORMAL);
  347.             }
  348.             }
  349.         }
  350.         if(bQuickLoad)
  351.         {
  352.         if(iDropButton-1 >= 0)
  353.             {
  354.             iDropped = iDropButton-1;
  355.             AppButton[iDropped] = AppButtonDefault;
  356.             DragQueryFile((HANDLE) wParam, 0, szDropFile, sizeof(szDropFile));
  357.             strcpy(AppButton[iDropped].IcoName, szDropFile);
  358.             strcpy(AppButton[iDropped].ProgName, szDropFile);
  359.             SaveButton(iDropped);
  360.             DestroyIcon(hIcon[iDropped]);
  361.             hIcon[iDropped] = ExtractIcon(hInst, AppButton[iDropped].IcoName, AppButton[iDropped].IconNumber);
  362.             if(hIcon[iDropped] == (HICON) 1)
  363.             hIcon[iDropped] = NULL;
  364.             InvalidateRect(hWndButton[iDropButton], NULL, FALSE);
  365.             UpdateWindow(hWndButton[iDropButton]);
  366.             }
  367.         }
  368.         DragFinish((HANDLE) wParam);
  369.         return 0;
  370.  
  371.     case WM_LBUTTONDOWN:    // Allows moving of a whole window
  372.         SetCursor(LoadCursor(NULL, IDC_SIZE));
  373.         bMoveButton = TRUE;
  374.         return(DefWindowProc(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, lParam));
  375.  
  376.     case WM_MOVE:
  377.         if(bMoveButton)
  378.         {
  379.         bMoveButton = FALSE;
  380.         if(MessageBox(NULL,"Save AppMore's new position",szTitleName,MB_YESNO) ==IDYES)
  381.             {
  382.             /* horizontal position */
  383.             AppSystem.Left = (int) LOWORD(lParam);
  384.             /* vertical position */
  385.             AppSystem.Top = (int) HIWORD(lParam);
  386.             strcpy(SystemSection, AppSystem.SectionName);
  387.             strcat(SystemSection, "_System");
  388.             sprintf(szBuffer,"%d", AppSystem.Left);
  389.             WritePrivateProfileString(SystemSection, LEFT, szBuffer, INI_FILE);
  390.             sprintf(szBuffer,"%d", AppSystem.Top);
  391.             WritePrivateProfileString(SystemSection, TOP, szBuffer, INI_FILE);
  392.             }
  393.         }
  394.         return 0;
  395.  
  396.     case WM_ACTIVATEAPP:
  397.         if(wParam == 0)
  398.         if(GetActiveWindow() != NULL)
  399.             if(iActive != 0)
  400.             {
  401.             AppButton[iActive-1].hWndApp = GetActiveWindow();
  402.             if(AppButton[iActive-1].ShowMode == 3)
  403.                 SetWindowPos(AppButton[iActive-1].hWndApp,
  404.                      NULL,
  405.                      AppMaxSize.left,
  406.                      AppMaxSize.top,
  407.                      AppMaxSize.width,
  408.                      AppMaxSize.height,
  409.                      SWP_NOACTIVATE | SWP_NOZORDER);
  410.             if(AppButton[iActive-1].Close)
  411.                 AppButton[iActive-1].Close = !IsDosWindow(AppButton[iActive-1].hWndApp);
  412.             if(AppButton[iActive-1].Close)
  413.                 AppButton[iActive-1].ProgStatus = ALIVE;
  414.             else
  415.                 AppButton[iActive-1].ProgStatus = NOTALIVE;
  416.             iActive = 0;
  417.             InvalidateRect(hWndCurrentButton, (LPRECT) NULL, FALSE);
  418.             UpdateWindow(hWndCurrentButton);
  419.             }
  420.         return 0;
  421.  
  422.        case WM_DESTROY:    // kill the whole program
  423.         DragAcceptFiles(hWnd, FALSE);
  424.         FreeAppMoreResources();
  425.         KillTimer(hWnd, ID_TIMER);
  426.         PostQuitMessage(0);
  427.         return 0;
  428.     }
  429.     return DefWindowProc(hWnd, message, wParam, lParam);
  430.     } /* end WndProc */
  431.